use std::sync::Arc;
use attestation_common::execute_sql_file;
use attestation_common::rdb::get_connection;
use log::info;
use sea_orm::DatabaseConnection;

// create db pool
pub async fn get_db_connect() -> Result<Arc<DatabaseConnection>, Box<dyn std::error::Error>> {
    let conn = get_connection().await?.clone();
    info!("DB pool create success!");
    info!("will init DB sql file!");
    let db_version = "v1".to_string();
    execute_sql_file(&conn, &db_version).await?;
    info!("init DB sql file success!");
    Ok(conn)
}
